<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="牧云汇平台ID:">
              <a-input v-model:value.trim="where.hzaxxId" placeholder="请输入牧云汇平台ID" allow-clear />
            </a-form-item>
            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>
			
          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="cameraId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          :scroll="{ x: 'max-content' }"
        >
          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>

            <!-- 其他列的模板 -->
            <template v-if="column.key === 'onlineStatusColumn'">
              <a-tag v-if="record.onlineStatus == 1" color="green">在线</a-tag>
              <a-tag v-else color="red">离线</a-tag>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>
  </div>
</template>

<script>
import { DeviceAiEdgeCameraApi } from '@/api/property/aiedgecomputer/DeviceAiEdgeCameraApi';
import {message} from 'ant-design-vue';
export default {
  name: 'DeviceAiedgecomputerCamera',
  components: {
  },
  props: {
    data: Object
  },
  async mounted() {

  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '相机ID',
          dataIndex: 'cameraId'
        },
        {
          title: '牧云汇平台ID',
          dataIndex: 'hzaxxId'
        },
        {
          title: '设备名称',
          dataIndex: 'name'
        },
        {
          title: '排序',
          dataIndex: 'orderNum'
        },
        {
          title: 'ip',
          dataIndex: 'cameraIp',
          customRender: function(row) {
            let str = "";
            if (row.record.cameraIp) {
              str = row.record.cameraIp;
            }
            if (row.record.port) {
              str += ":" + row.record.port;
            }
            return str;
          }
        },
        {
          title: '在线状态',
          key: 'onlineStatusColumn',
          dataIndex: 'onlineStatus',
          width: 70,
        },
        {
          title: '状态更新时间',
          dataIndex: 'onlineStatusTime'
        },
      ],
      // 表格搜索条件
      where: {
        "edgeRecordId" : this.data.recordId
      },
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2025/06/09 23:41
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2025/06/09 23:41
     */
    reset() {
      this.where.hzaxxId = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2025/06/09 23:41
     */
    async remove(row) {
      const result = await DeviceAiEdgeCameraApi.delete({ cameraId: row.cameraId });
      message.success(result.message);
      this.reload();
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2025/06/09 23:41
     */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
     /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
     datasource({ page, limit, where, orders }) {
      return DeviceAiEdgeCameraApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>